<?php

namespace api\modules\backend\controllers;

use api\modules\backend\models\ApplyGift;
use api\modules\backend\models\Bus;
use api\modules\backend\models\Driver;
use api\modules\backend\models\Gift;
use api\modules\backend\models\Guide;
use api\modules\backend\models\Hotel;
use api\modules\backend\models\Journey;
use api\modules\backend\models\Apply;
use api\modules\backend\models\JourneyGift;
use api\modules\backend\models\Line;
use api\modules\backend\models\Member;
use api\modules\backend\models\RestaurantMeal;
use PhpOffice\PhpSpreadsheet\Reader\Xlsx;
use yii\data\Pagination;
use api\modules\backend\models\UploadForm;
use yii\web\UploadedFile;
use common\commands\Common;
use Yii;
use yii\filters\auth\QueryParamAuth;

/**
 * Dashboard Controller API
 *
 * @author Fong <xiaofeng.zhang@suppernovachina.com>
 */
class DashboardController extends ControllerBase
{
    public $modelClass = 'api\modules\v1\models\Line';
    private $notDeleted = 0; //未删除状态
    private $deleted = 1; //已删除状态
    private $active = 1;

    public function behaviors()
    {
        $behaviors = parent::behaviors();
        $behaviors['authenticator'] = [
            'class' => QueryParamAuth::className(),
            'optional' => [],
        ];
        $behaviors['authenticator']['except'] = ['options'];

        return $behaviors;
    }

    public function actionIndex()
    {
        $where = [
            'is_deleted' => $this->notDeleted
        ];

        $lineModelClass = new Line();
        $lineCount = $lineModelClass::find()->where($where)->count();

        $memberModelClass = new Member();
        $memberCount = $memberModelClass::find()->where($where)->count();

        $busModelClass = new Bus();
        $busCount = $busModelClass::find()->where($where)->count();

        $guideModelClass = new Guide();
        $guideCount = $guideModelClass::find()->where($where)->count();

        $driverModelClass = new Driver();
        $driverCount = $driverModelClass::find()->where($where)->count();

        $hotelModelClass = new Hotel();
        $hotelCount = $hotelModelClass::find()->where($where)->count();

        $restaurantMealModelClass = new RestaurantMeal();
        $restaurantMealCount = $restaurantMealModelClass::find()->where($where)->count();

        $giftModelClass = new Gift();
        $giftCount = $giftModelClass::find()->where($where)->count();

        $data = [
            'statistics' => [
                'line' => [
                    'title' => '路线数量',
                    'lineCount' => $lineCount,
                ],
                'member' => [
                    'title' => '会员数量',
                    'memberCount' => $memberCount,
                ],
                'bus' => [
                    'title' => '大巴数量',
                    'busCount' => $busCount,
                ],
                'guide' => [
                    'title' => '导游数量',
                    'guideCount' => $guideCount,
                ],
                'driver' => [
                    'title' => '司机数量',
                    'driverCount' => $driverCount,
                ],
                'hotel' => [
                    'title' => '酒店数量',
                    'hotelCount' => $hotelCount,
                ],
                'restaurantMeal' => [
                    'title' => '餐厅数量',
                    'restaurantMealCount' => $restaurantMealCount,
                ],
                'gift' => [
                    'title' => '礼品数量',
                    'giftCount' => $giftCount
                ],
            ]
        ];

        $this->success($data);
    }
}